# -*- coding: utf-8 -*-
# @project: huawang-api20230914
# @file： content_page.py
# @Time：2023/8/1 16:25
# @Author：lizhixiong
"""内容下的所有页面"""
from time import sleep

import allure
from selenium.webdriver.common.by import By

from common.commin.commin import object_left_click, object_send_keys
from common.log.log import log
from data.names import EditContentSel, PublicSel
from po.jinhua.ht.jinhua_ht_main.jinhua_base import JHBase


class ContentPage(JHBase):
    """
    内容菜单下的所有页面
    """

    @allure.step('新增敏感词')
    def add_sensitive_words(self, keyword):
        try:
            log.info('*****新增敏感词*****')
            object_left_click(self.driver, EditContentSel.el_add_sensitive())
            object_send_keys(self.driver, EditContentSel.el_sen_input(), keyword)
            object_left_click(self.driver, EditContentSel.el_list_dropdown())
            object_left_click(self.driver, EditContentSel.el_hei())
            object_left_click(self.driver, PublicSel.el_submit_button())
        except Exception as e:
            log.error(f'新增敏感词出现错误，异常为{e}')
            raise e

    @allure.step('搜索敏感词')
    def search_sensitive_words(self, keyword):
        try:
            log.info('*****搜索敏感词*****')
            object_send_keys(self.driver, EditContentSel.el_search_input(), keyword)
            object_left_click(self.driver, PublicSel.el_icon_search_2())
            sleep(0.5)
        except Exception as e:
            log.error(f'搜索敏感词出现错误，异常为{e}')
            raise e

    @allure.step('删除敏感词')
    def delete_sensitive_words(self, keyword):
        try:
            log.info('*****搜索敏感词*****')
            self.search_sensitive_words(keyword)
            del_ele = self.driver.find_elements(By.XPATH, "//span[contains(text(),'删除')]")
            del_ele[-1].click()  # 点击删除
            object_left_click(self.driver, PublicSel.el_ok_button())  # 弹框点击确定
            sleep(0.5)
        except Exception as e:
            log.error(f'搜索敏感词出现错误，异常为{e}')
            raise e
